package com.blog.controller;

import com.blog.service.ArticleService;
import com.blog.service.impl.ArticleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/DeleteArticleServlet.do")
public class DeleteArticleServlet extends HttpServlet {

    ArticleService articleService=new ArticleServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        String articleId = req.getParameter("articleId");
        try {
            int count= articleService.deleteById(articleId);
            resp.getWriter().write("<script>alert('文章删除成功！');location.href='/Blog/GoAdminServlet.do';</script>");
        } catch (IOException e) {
            e.printStackTrace();
            resp.getWriter().write("<script>alert('文章删除失败！');location.href='/Blog/GoAdminServlet.do';</script>");
        }
    }
}
